package com.winsdom.controller;

import com.winsdom.dto.FeecategoryThreeNodes;
import com.winsdom.dto.expenditure.ExpenditureDto;
import com.winsdom.dto.expenditure.ExpenditureUpsertDTO;
import com.winsdom.entity.FeeCategory;
import com.winsdom.result.Result;
import com.winsdom.service.IExpenditureService;
import com.winsdom.vo.expenditure.ExpenditureVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/expenditure")
@Api(tags = "费项管理接口", description = "费项信息管理接口")
public class ExpenditureController {

    @Autowired
    private IExpenditureService expenditureService;

    @PostMapping("/list")
    @ApiOperation(value = "根据查询条件获取费项列表信息")
    public Result queryExpenditures(ExpenditureDto expenditureDto) {
        List<ExpenditureVo> expenditureVos = expenditureService.getExpenditureList(expenditureDto);
        return Result.success(expenditureVos);
    }

    @GetMapping("/get/feeCategory")
    @ApiOperation(value = "获取费项分类列表")
    public Result getFeeCategory() {
        List<FeeCategory> feeCategoryVos = expenditureService.getFeeCategoryList();
        return Result.success(feeCategoryVos);
    }

    @GetMapping("/feeCategory/nodes")
    @ApiOperation(value = "获取费项分类树节点")
    public Result getFeeCategoryNodes() {
        List<FeecategoryThreeNodes> feeCategoryVos = expenditureService.getFeeCategoryNodes();
        return Result.success(feeCategoryVos);
    }

    @PostMapping("/add/expenditure")
    @ApiOperation(value = "新增费项")
    public Result addExpenditure(@RequestBody @Valid ExpenditureUpsertDTO dto) {
        Result result = expenditureService.addExpenditure(dto);
        return result;
    }

    @GetMapping("/add/formula")
    @ApiOperation(value = "根据计费性质获取到对应的公式列表")
    public Result getFormula(@RequestParam("nature") Integer nature) {
        Result result=  expenditureService.getFormula(nature);
        return result;
    }

    @GetMapping("/show/expenditure/{expenditureId}")
    @ApiOperation(value = "根据费项id获取费项详情(计费公式，单价)")
    public Result showExpenditure(@PathVariable("expenditureId") Integer expenditureId) {
        Result result=  expenditureService.showExpenditure(expenditureId);
        return result;
    }

    @GetMapping("/stop/expenditure/{expenditureId}")
    @ApiOperation(value = "停用费项")
    public Result stopExpenditure(@PathVariable("expenditureId") Integer expenditureId) {
        Result result=  expenditureService.stopExpenditure(expenditureId);
        return result;
    }

    @PostMapping("/expenditure/update")
    @ApiOperation(value = "修改费项")
    public Result updateExpenditure(@Valid @RequestBody ExpenditureUpsertDTO dto) {
        Result result=  expenditureService.updateExpenditure(dto);
        return result;
    }
}
